import numpy as np
def S_word(N,K,p):
    if K%2:
        print("error")
    A=np.zeros((N,N))
    b=int(K/2)
    for i in range(N):
        for j in range(b+1):
            A[i,i-j]=1
            A[i-j,i]=1
    for i in range(b+1):
        for j in range(b+1-i):
            A[N-i-1,0+j]=1
            A[0+j,N-i-1] = 1
    n=np.random.normal(size=[N])
    n= abs(n)/(max(n)-min(n))
    node_list=n<p
    for i in range(1,b):
        if (node_list[i]):
            for j in range(1,i+1):
                while 1:
                    new_node=np.random.randint(N)
                    if (new_node!=i)and(A[new_node,i]!=1):
                        A[i,new_node]=1
                        break
                if i<N-j:
                    A[i,i+j]=0
                    A[i+j,i]=0
                else:
                    A[i-N+j,i]=0
                    A[i,i-N+j]=0
    print(A)
S_word(20,6,0.4)



